<?php
/*
 * @Author: 天羽落星辰
 * @Date: 2020-07-03 17:54:10
 * @LastEditors: 天羽落星辰
 * @LastEditTime: 2020-07-14 18:05:28
 * @Description: file content
 */ 

namespace app\admin\controller;

use think\Db;
use app\common\controller\Backend;

/**
 * 1.04 会员活力值变动日志管理
 *
 * @icon fa fa-circle-o
 */
class UserScoreLog extends Backend
{
    
    /**
     * UserScoreLog模型对象
     * @var \app\admin\model\UserScoreLog
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\UserScoreLog;

    }
    
    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */
    
     // 确认入账
    public function disable()
    {   
        $id = input('ids');
        $user_score = $this->model->where('id',$id)->whereIn('type','3,4')->whereIn('disable',1)->find();
        if($user_score){
            try {
                $a1 =db('user')->where('id',$user_score['uid'])->setInc('score',$user_score['money']);
                $a2 = $this->model->update(['id' => $user_score['id'], 'disable' => 0]);
                if(!$a1 && !$a2){
                    throw new \Exception("确认入账失败", 1);
                }
                Db::commit(); 
            } catch (\Exception $th) {
                Db::rollback(); //km++
                $this->error($th->getMessage());
            }
            $this->success('确认入账成功');
        }
        $this->error('请刷新!');
    }

}
